package store.lunangangster.nodeflow.util;

import store.lunangangster.nodeflow.exception.ConvertException;

/**
 * 用于类型转化的工具类
 *
 * @author cwk
 * @version 1.0
 */
public class Converter {
  public static <T> T convert(Object source, Class<T> clazz) {
    if (source == null) {
      return null;
    }
    if (clazz == null) {
      throw new ConvertException("Target class be null");
    }
    if (!clazz.isAssignableFrom(source.getClass())) {
      throw new ConvertException(String.format("Incompatible convert from %s to %s", source.getClass(), clazz));
    }
    return (T) source;
  }
}
